****Democratization boost or bust? Electoral turnout after democratic transitions****
****Created by Roman-Gabriel Olar on 01/06/2022***
****Last modified on 03/07/2023****

set more off
set scheme plottig
cd "*set your own working directort"
use "Macro_Analysis.dta", clear

**************
***Figure 1***
**************
sort ccode year 
gen turnout_fig=VoterTurnout
replace turnout_fig=v2eltrnout if turnout_fig==.
browse year gwf_country VoterTurnout v2eltrnout turnout_fig if gwf_dem==1
by ccode: carryforward turnout_fig, gen(ts_turnout)
sort year ccode
by year: egen ts_turnout_estab=mean(ts_turnout) if estab==1
by year: egen ts_turnout_new=mean(ts_turnout) if estab==0
by year: carryforward ts_turnout_estab, replace
label variable ts_turnout "Country of observation"
label variable ts_turnout_estab "Established democracies"
label variable ts_turnout_new "Electoral turnout in new democracies"
egen founding_mean=mean(VoterTurnout) if founding_idea==1
carryforward founding_mean, replace
replace founding_mean=founding_mean-VoterTurnout if founding_idea==1&gwf_country=="Poland"
replace founding_mean=founding_mean-VoterTurnout if founding_idea==1&gwf_country=="Romania"

***Generate Figure***
line ts_turnout ts_turnout_estab year if (gwf_country=="Poland" & year>1989), xlab(1990(5)2015) ///
		ylab(40(10)100) name(poland, replace) legend(col(2) pos(6)) title("Poland") xtitle("") ytitle("Electoral turnout")
line ts_turnout ts_turnout_estab year if (gwf_country=="Romania" & year>1989), xlab(1990(5)2015) ///
		ylab(40(10)100) name(romania, replace) legend(col(2) pos(6)) title("Romania") xtitle("") ytitle("Electoral turnout")
graph combine poland romania, col(2)


****************************************************************
**-----------------ELECTION LEVEL ANALYSIS--------------------**
****************************************************************
use "Macro_Analysis.dta", clear

tab e_regionpol, gen(reg_fe)
global model "i.dec_* i.e_regionpol"
global model2 "yr_of_dem l_v2x_polyarchy i.dec_* i.e_regionpol"

global main " l_wbpopln l_ln_gdppc proportional comp_vote conc majoritarian elec_type"
global inst "proportional presidential comp_vote v2elage"
global past "pre_gwf_party pre_gwf_personal pre_gwf_military"

******************
*****TABLE 1******
******************

***Model 1 - All elections
xtreg VoterTurnout i.crt_trans i.gwf_trans $model $main if transition<3, re robust cluster(ccode)
outreg2 using macro.doc, label bracket bdec(3) sdec(3) replace

***Model 2 - Founding elections
xtreg VoterTurnout i.crt_trans i.gwf_trans i.founding_idea $model $main if transition<3, re robust cluster(ccode)
outreg2 using macro.doc, label bracket bdec(3) sdec(3) append

***Model 3 - New democracies
xtreg VoterTurnout i.crt_trans i.founding_idea $model $main if transition==1, re robust cluster(ccode)
outreg2 using macro.doc, label bracket bdec(3) sdec(3) append

****Model 4 - Transition type & Founding elections Vs Established democracies
xtreg VoterTurnout i.crt_trans i.gwf_trans i.founding_idea $model $main if sample==1, re robust cluster(ccode)
outreg2 using macro.doc, label bracket bdec(3) sdec(3) append

**********************************************************************
***********ROBUSTNESS TESTS FOR ELECTION-LEVEL ANALYSIS***************
**********************************************************************

******************
****TABLE A2.1****
******************

***Model A2.1***
xtreg VoterTurnout crt_trans count_idea_dem $model $main if transition==1, re robust cluster(ccode)
outreg2 using count.doc, label bracket bdec(3) sdec(3) replace
***Figure A2.1
margins, at(count_idea_dem=(1(1)25))
marginsplot, xlab(1(4)25) xtitle("No. of elections since transition") ytitle("Predicted turnout rate") title("")


******************
****TABLE A2.2****
******************
***Generate sample for Panel corrected standard errors model***
xtreg VoterTurnout i.crt_trans i.gwf_trans2 i.founding_idea $model $main if transition<3, re robust cluster(ccode)
keep if e(sample)

***Prepare panel data
sort ccode elec_date NELDAround Electiontype
by ccode: gen order=_n
xtset ccode order

*************************************
***Tests for autocorrelation and heteroskedasticity***
*************************************
***Autocorrelation test - None present
xtserial VoterTurnout crt_trans gwf_trans founding_idea reg_fe* dec_* $main if transition<3

**Heteroskedasticiy test
reg VoterTurnout i.crt_trans i.gwf_trans2 i.founding_idea $model $main if transition<3
estat hettest

*************************************
***Panel corrected standard errors***
*************************************

***Model A2.2 - All elections
xtpcse VoterTurnout i.crt_trans i.gwf_trans $model $main if transition<3, corr(ar 1)
outreg2 using pcse.doc, label bracket bdec(3) sdec(3) replace

***Model A2.3 - Founding elections
xtpcse VoterTurnout i.crt_trans i.gwf_trans i.founding_idea $model $main if transition<3, corr(ar 1)
outreg2 using pcse.doc, label bracket bdec(3) sdec(3) append

***Model A2.4 - New democracies
xtpcse VoterTurnout i.crt_trans i.founding_idea $model $main if transition==1, corr(ar 1)
outreg2 using pcse.doc, label bracket bdec(3) sdec(3) append



********************
*****TABLE A2.3*****
********************

use "Macro_Analysis.dta", clear
tab e_regionpol, gen(reg_fe)
global model "i.dec_* i.e_regionpol"
global model2 "yr_of_dem l_v2x_polyarchy i.dec_* i.e_regionpol"

global main " l_wbpopln l_ln_gdppc proportional comp_vote conc majoritarian elec_type"
global inst "proportional presidential comp_vote v2elage"
global past "pre_gwf_party pre_gwf_personal pre_gwf_military"

***Disaggregating transition types***

***Model A2.5 - All elections
xtreg VoterTurnout i.mob_trans2 i.elite_trans i.election_trans i.cw_trans i.foreign_trans i.indep_trans $model $main if transition<3, re robust cluster(ccode)
outreg2 using trans_all.doc, label bracket bdec(3) sdec(3) replace

***Model A2.6 - Founding elections
xtreg VoterTurnout i.mob_trans2 i.elite_trans i.election_trans i.cw_trans i.foreign_trans i.indep_trans i.founding_idea $model $main if transition<3, re robust cluster(ccode)
outreg2 using trans_all.doc, label bracket bdec(3) sdec(3) append

***Model A2.7 - New democracies (foreign imposed as counter-factual)
xtreg VoterTurnout i.mob_trans2 i.elite_trans i.election_trans i.cw_trans i.indep_trans i.founding_idea $model $main if transition==1, re robust cluster(ccode)
outreg2 using trans_all.doc, label bracket bdec(3) sdec(3) append

***Model A2.8 - Founding vs established 
xtreg VoterTurnout i.mob_trans2 i.elite_trans i.election_trans i.cw_trans i.foreign_trans i.indep_trans i.founding_idea $model $main if sample==1, re robust cluster(ccode)
outreg2 using trans_all.doc, label bracket bdec(3) sdec(3) append


********************
*****TABLE A2.4*****
********************

***Controlling for mobilization at transition***

***Model A2.9 - All elections
xtreg VoterTurnout i.crt_trans i.gwf_trans length $model $main if transition<3, re robust cluster(ccode)
outreg2 using length.doc, label bracket bdec(3) sdec(3) replace

***Model A2.10 - Founding elections
xtreg VoterTurnout i.crt_trans i.gwf_trans i.founding_idea length $model $main if transition<3, re robust cluster(ccode)
outreg2 using length.doc, label bracket bdec(3) sdec(3) append

***Model A2.11 - New democracies
xtreg VoterTurnout i.crt_trans i.founding_idea length $model $main if transition==1, re robust cluster(ccode)
outreg2 using length.doc, label bracket bdec(3) sdec(3) append

****Model A2.12 - Transition type & Founding elections Vs Established democracies
xtreg VoterTurnout i.crt_trans i.gwf_trans i.founding_idea length $model $main if sample==1, re robust cluster(ccode)
outreg2 using length.doc, label bracket bdec(3) sdec(3) append


********************
*****TABLE A2.5*****
********************

***Testing for years of democracy and levels of democracy***

***Model A2.13 - All elections
xtreg VoterTurnout i.crt_trans i.gwf_trans $model2 $main if transition<3, re robust cluster(ccode)
outreg2 using polyarchy.doc, label bracket bdec(3) sdec(3) replace

***Model A2.14 - Founding elections
xtreg VoterTurnout i.crt_trans i.gwf_trans i.founding_idea $model2 $main if transition<3, re robust cluster(ccode)
outreg2 using polyarchy.doc, label bracket bdec(3) sdec(3) append

***Model A2.15 - New democracies
xtreg VoterTurnout i.crt_trans i.founding_idea $model2 $main if transition==1, re robust cluster(ccode)
outreg2 using polyarchy.doc, label bracket bdec(3) sdec(3) append

****Model A2.16 - Transition type & Founding elections Vs Established democracies
xtreg VoterTurnout i.crt_trans i.gwf_trans i.founding_idea $model2 $main if sample==1, re robust cluster(ccode)
outreg2 using polyarchy.doc, label bracket bdec(3) sdec(3) append


********************
*****TABLE A2.6*****
********************

***Share of population between 15 and 24 years of age***

***Model A2.17 - All elections
xtreg VoterTurnout i.crt_trans i.gwf_trans pre24 $model $main if transition<3, re robust cluster(ccode)
outreg2 using age.doc, label bracket bdec(3) sdec(3) replace

***Model A2.18 - Founding elections
xtreg VoterTurnout i.crt_trans i.gwf_trans i.founding_idea pre24 $model $main if transition<3, re robust cluster(ccode)
outreg2 using age.doc, label bracket bdec(3) sdec(3) append

***Model A2.19 - New democracies
xtreg VoterTurnout i.crt_trans i.founding_idea pre24 $model $main if transition==1, re robust cluster(ccode)
outreg2 using age.doc, label bracket bdec(3) sdec(3) append

****Model A2.20 - Transition type & Founding elections Vs Established democracies
xtreg VoterTurnout i.crt_trans i.gwf_trans i.founding_idea pre24 $model $main if sample==1, re robust cluster(ccode)
outreg2 using age.doc, label bracket bdec(3) sdec(3) append


****************************************************************
**----------------INDIVIDUAL LEVEL ANALYSIS-------------------**
****************************************************************

use "Micro_Analysis.dta", clear

global formative "yr_crt_exper15_29 yr_gwf_exper15_29"
global formative2 "yr_crt_exper20_29 yr_gwf_exper20_29"
global experience "yr_crt_exper15 yr_gwf_exper15"
global old "yr_crt_exper30 yr_gwf_exper30"
global ind_iv "i.educ_combi working female"

global model "age age2 i.e_regionpol"
global model2 "age age2 yr_of_dem l_v2x_polyarchy i.e_regionpol"

global main "l_wbpopln l_ln_gdppc proportional comp_vote conc majoritarian"
global inst "proportional presidential comp_vote v2elage"
global past "pre_gwf_party pre_gwf_personal pre_gwf_military"

***Create analytical weights***
bysort country: gen nob2=_N

********************
**TABLE 2 and A3.1**
********************

**Model 5
mixed turnout $formative $old $model i.data i.year if transition<3 || ccode:
outreg2 using micro.doc, label bracket bdec(3) sdec(3) replace

**Model 6
mixed turnout $formative $old $model $ind_iv i.data i.year if transition<3 || ccode:
outreg2 using micro.doc, label bracket bdec(3) sdec(3) append

**Model 7
mixed turnout $formative $old $model $ind_iv $main i.data i.year if transition<3 || ccode:
outreg2 using micro.doc, label bracket bdec(3) sdec(3) append

**Model 8
mixed turnout yr_crt_exper15_29 yr_crt_exper30 $model $ind_iv $main i.data i.year if transition==1 || ccode:
outreg2 using micro.doc, label bracket bdec(3) sdec(3) append

**************************************************************************************
***SEE SECTION TABLE A3.3 FOR DETAILS ON THE GENERALIZED ADDITIVE MODELS ESTIMATION***
**************************************************************************************

********************************************************************
*******ROBUSTNESS TESTS FOR THE INDIVIDUAL LEVEL ANALYSIS***********
********************************************************************

********************
*****TABLE A3.2****
********************

****Disaggregating transition types*****
global trans_form "yr_elite_trans_exper15_29 yr_election_trans_exper15_29 yr_cw_trans_exper15_29 yr_foreign_trans_exper15_29 yr_indep_trans_exper15_29 yr_mob2_trans_exper15_29"
global trans_old "yr_elite_trans_exper30 yr_election_trans_exper30 yr_cw_trans_exper30 yr_foreign_trans_exper30 yr_indep_trans_exper30 yr_mob2_trans_exper30"

global trans_form_new "yr_elite_trans_exper15_29 yr_election_trans_exper15_29 yr_cw_trans_exper15_29 yr_indep_trans_exper15_29 yr_mob2_trans_exper15_29"
global trans_old_new "yr_elite_trans_exper30 yr_election_trans_exper30 yr_cw_trans_exper30 yr_indep_trans_exper30 yr_mob2_trans_exper30"

***Model A3.1
mixed turnout $trans_form $trans_old $model i.data i.year if transition<3 || ccode:
outreg2 using trans.doc, label bracket bdec(3) sdec(3) replace

**Model A3.2
mixed turnout $trans_form $trans_old $model $ind_iv i.data i.year if transition<3 || ccode:
outreg2 using trans.doc, label bracket bdec(3) sdec(3) append

**Model A3.3
mixed turnout $trans_form $trans_old $model $ind_iv $main i.data i.year if transition<3 || ccode:
outreg2 using trans.doc, label bracket bdec(3) sdec(3) append

**Model A3.4
mixed turnout $trans_form $model $ind_iv $main i.data i.year if transition==1 || ccode:
outreg2 using trans.doc, label bracket bdec(3) sdec(3) append

********************
*****TABLE A3.3*****
********************

****Prepare data for GAM estimation****

keep if transition==1
sum age_yr_crt age_yr_gwf age_yr_gwf2
foreach var of varlist age_yr_crt age_yr_gwf age_yr_gwf2 {
replace `var'=0 if `var'<0
}
sum age_yr_crt age_yr_gwf age_yr_gwf2
recode age_yr_crt (80/99=80)
recode age_yr_gwf (80/94=80)
recode age_yr_gwf2 (80/94=80)
sum age_yr_crt age_yr_gwf age_yr_gwf2
recode conc (.=0)
recode elec_type (0=1) (1=2) (.=0)
recode idea .=0
saveold "gam_micro.dta", v(12) replace

***Run the R Script called GAM.R to replicate Figure 2 and 3 from the main text, models from Table A3.3 and Figures A3.1 to A3.4***


********************
*****TABLE A3.4*****
********************

****OVER-REPORTING*****

***Generate average reported turnout per country-year
use "Micro_Analysis.dta", clear
collapse (mean) turnout, by(ccode year)
save agg_turnout.dta, replace

***Generate average turnout in election per country-year
use "Macro_Analysis.dta", clear
gen over=1 if transition==1
replace over=0 if transition==2

collapse (mean) VoterTurnout (max) over, by (ccode year) 
sort ccode year
gen ts_turnout=VoterTurnout
by ccode: carryforward ts_turnout, replace
merge 1:1 ccode year using "agg_turnout.dta", keep(master match)
drop _m

gen v2_trnout=ts_turnout/100
gen diff_trnout=turnout-v2_trnout if over!=.
sum diff_trnout

label variable v2_trnout "Election turnout"
label variable diff_trnout "Turnout over-reporting"
label variable over "1=New democracy/0=Established democracy"

merge 1:m ccode year using "Macro_Analysis.dta", keep(master match)
global model "i.dec_* i.e_regionpol"
global model2 "yr_of_dem l_v2x_polyarchy i.dec_* i.e_regionpol"
global main " l_wbpopln l_ln_gdppc proportional comp_vote conc majoritarian elec_type"

***Prepare the data***
sort ccode year
by ccode: carryforward conc, replace
by ccode: carryforward elec_type, replace

***Capture democracy type (0=consolidated/1=civil resistance/2=other transition type)
gen type=0 if over==0
replace type=1 if crt_trans==1
replace type=2 if gwf_trans==1

***Estimation of over-reporting
xtreg diff_trnout i.type $model $main, re cluster(ccode)
outreg2 using over.doc, label bracket bdec(3) sdec(3) replace


********************
*****TABLE A3.5*****
********************

****EXPOSURE TO Mobilization*****
use "Macro_Analysis.dta", clear

**Generate measure of exposure to mobilization after 15 years of age**

gen age_trans= age_yr_crt
replace age_trans=age_yr_gwf if age_trans==.
gen trans_exp=1 if age_trans>14 & age_trans!=.
replace trans_exp=0 if trans_exp==.

***Capture individuals eligible for exposure to mobilization
gen potential_exposure=age_trans-15
recode potential_exposure (-63/-1=0)
tab potential_exposure

***Capture no of years exposed to mobilization
gen exper_mob=length if potential_exposure>=14 & potential_exposure!=.
replace exper_mob=potential_exposure if potential_exposure<14 & potential_exposure!=. & exper_mob==. & potential_exposure<=length
replace exper_mob=length if potential_exposure<14 & potential_exposure!=. & exper_mob==. & potential_exposure>length
recode exper_mob .=0
rename exper_mob exper_length_mob

**Model A3.9
mixed turnout $formative $old exper_length_mob $model i.data i.year if transition<3 || ccode:
outreg2 using mobilization.doc, label bracket bdec(3) sdec(3) replace

**Model A3.10
mixed turnout $formative $old exper_length_mob $model $ind_iv i.data i.year if transition<3 || ccode:
outreg2 using mobilization.doc, label bracket bdec(3) sdec(3) append

**Model A3.11
mixed turnout $formative $old exper_length_mob $model $ind_iv $main i.data i.year if transition<3 || ccode:
outreg2 using mobilization.doc, label bracket bdec(3) sdec(3) append

**Model A3.12
mixed turnout yr_crt_exper15_29 yr_crt_exper30 exper_length_mob $model $ind_iv $main i.data i.year if transition==1 || ccode:
outreg2 using mobilization.doc, label bracket bdec(3) sdec(3) append



********************
*****TABLE A3.6*****
********************

****Years of democracy and level of liberal democracy*****

**Model A3.13
mixed turnout $formative $old $ind_iv $model2 $main i.data i.year if transition<3 || ccode:
outreg2 using vdem.doc, label bracket bdec(3) sdec(3) replace

**Model A3.14
mixed turnout yr_crt_exper15_29 yr_crt_exper30 $model2 $ind_iv $main i.data i.year if transition==1 || ccode:
outreg2 using vdem.doc, label bracket bdec(3) sdec(3) append


********************
*****TABLE A3.7*****
********************

****Previous regime and number of elections*****
global past "prev_aut_elec pre_gwf_party pre_gwf_personal pre_gwf_military"

**Model A3.15
mixed turnout $formative $old $model $ind_iv $past $main i.data i.year if transition<3 || ccode:
outreg2 using past.doc, label bracket bdec(3) sdec(3) replace

**Model A3.16
mixed turnout yr_crt_exper15_29 yr_crt_exper30 $model $ind_iv $past $main i.data i.year if transition==1 || ccode:
outreg2 using past.doc, label bracket bdec(3) sdec(3) append


********************
*****TABLE A3.8*****
********************

****FIXED EFFECTS ESTIMATION*****

**Model A3.17
reg turnout $formative $old $model i.data i.year i.ccode if transition<3 
outreg2 using fe.doc, label bracket bdec(3) sdec(3) replace

**Model A3.18
reg turnout $formative $old $model $ind_iv i.data i.year i.ccode if transition<3 
outreg2 using fe.doc, label bracket bdec(3) sdec(3) append

**Model A3.19
reg turnout $formative $old $model $ind_iv $main i.data i.year i.ccode if transition<3 
outreg2 using fe.doc, label bracket bdec(3) sdec(3) append

**Model A3.20
reg turnout yr_crt_exper15_29 yr_crt_exper30 $model $ind_iv $main i.data i.year i.ccode if transition==1 
outreg2 using fe.doc, label bracket bdec(3) sdec(3) append


********************
*****TABLE A3.9*****
********************

****BIRTH COHORT DECADE FE*****

**Model A3.21
mixed turnout $formative $old $model i.coh_tab i.data i.year if transition<3 || ccode:
outreg2 using coh.doc, label bracket bdec(3) sdec(3) replace

**Model A3.22
mixed turnout $formative $old $model $ind_iv i.coh_tab i.data i.year if transition<3 || ccode:
outreg2 using coh.doc, label bracket bdec(3) sdec(3) append

**Model A3.23
mixed turnout $formative $old $model $ind_iv $main i.coh_tab i.data i.year if transition<3 || ccode:
outreg2 using coh.doc, label bracket bdec(3) sdec(3) append

**Model A3.24
mixed turnout yr_crt_exper15_29 yr_crt_exper30 $model $ind_iv $main i.coh_tab i.data i.year if transition==1 || ccode:
outreg2 using coh.doc, label bracket bdec(3) sdec(3) append


********************
*****TABLE A3.10****
********************

****WEIGHTS****

**Model A3.25
reg turnout $formative $old $model i.data i.year [aweight=nob2] if transition<3
outreg2 using weights.doc, label bracket bdec(3) sdec(3) replace

**Model A3.26
reg turnout $formative $old $model $ind_iv i.data i.year [aweight=nob2] if transition<3 
outreg2 using weights.doc, label bracket bdec(3) sdec(3) append

**Model A3.27
reg turnout $formative $old $model $ind_iv $main i.data i.year [aweight=nob2] if transition<3
outreg2 using weights.doc, label bracket bdec(3) sdec(3) append

**Model A3.28
reg turnout yr_crt_exper15_29 yr_crt_exper30 $model $ind_iv $main i.data i.year [aweight=nob2] if transition==1
outreg2 using weights.doc, label bracket bdec(3) sdec(3) append


**************************************************************
**************APPENDIX SUMMARY TABLES*************************	
**************************************************************

********************
******TABLE A1******
********************

**Table A1.1. Survey data summary
use "Micro_Analysis.dta", clear
collapse (count) turnout (max) yr_crt yr_gwf (lastnm) data, by(country year)
gen survey_year=1
collapse (max) yr_crt yr_gwf (sum) turnout survey_year, by(country)

***Table A1.2. Civil resistance transitions
use "Macro_Analysis.dta", clear
keep if crt_trans==1
collapse (max) yr_crt (lastnm) ccode, by(country_name)
replace country_name="Yemen" if country_name==""
rename yr_crt trans_year
merge 1:1 ccode trans_year using "CR_trans.dta", keep(match)
keep Country trans_year CampaignName


***Table A1.3. Capture country-survey-years included in analysis 
use "Micro_Analysis.dta", clear
collapse (lastnm) data, by(country year)
gen survey="World Values Survey" if data==0
replace survey="Americas Barometer" if data==3
replace survey="International Social Survey Project" if data==4
replace survey="Asian Barometer" if data==5
replace survey="Afrobarometer" if data==7
replace survey="Eurobarometer" if data==10
replace survey="European Social Survey" if data==12
replace survey="Comparative Study of Electoral Systems" if data==13


